package net.lab1024.sa.user.module.business.course.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.common.common.domain.PageResult;
import net.lab1024.sa.common.common.util.SmartPageUtil;
import net.lab1024.sa.user.module.business.course.dao.CourseTeacherDao;
import net.lab1024.sa.user.module.business.course.domain.form.CourseTeacherQueryForm;
import net.lab1024.sa.user.module.business.course.domain.vo.CourseTeacherVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 课程教练 Service
 *
 * @Author jabari
 * @Date 2023-08-05 17:50:44
 * @Copyright 51dev.cn
 */

@Service
public class CourseTeacherService {

    @Autowired
    private CourseTeacherDao courseTeacherDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<CourseTeacherVO> queryPage(CourseTeacherQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<CourseTeacherVO> list = courseTeacherDao.queryPage(page, queryForm);
        PageResult<CourseTeacherVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    public List<CourseTeacherVO> getCourseTeacherVOList(List<Integer> courseIds){


        return courseTeacherDao.selectByCourseIds(courseIds).stream().map(courseTeacherEntity -> {

            CourseTeacherVO courseTeacherVO = new CourseTeacherVO();
            BeanUtils.copyProperties(courseTeacherEntity, courseTeacherVO);

            return courseTeacherVO;
        }).collect(Collectors.toList());
    }


}
